<template>
  <div class="notic-bar">
    <img src="../Notice/laba.gif" class="notice-img"/>
    <div class="notice-bar-container">
      <div class="notice-bar__wrap">
        <div
          v-for="(item, index) in list"
          :key="index"
          class="notice-bar__wrap_text"
        >
          {{ item.conText}}
        </div>
      </div>
    </div>
  </div>
</template>
<script>
function splitWithCommas(str) {
  // 使用一个不太可能出现在原始字符串中的字符作为临时替换符，
  // 这里我们选择使用一个特殊的Unicode字符 `\uFFFF`。
  const tempChar = '\uFFFF';

  // 替换所有的逗号为临时字符
  let replacedStr = str.replace(/,/g, tempChar);

  // 根据临时字符拆分字符串
  let parts = replacedStr.split(tempChar);

  // 恢复每个部分中的逗号
  for (let i = 0; i < parts.length; i++) {
    parts[i] = parts[i].replace(new RegExp(tempChar, 'g'), ',');
  }

  return parts;
}

export default {
  data() {
    return {
      list: []
    };
  },
  methods: {
    getDataList(){
      this.$http({
        url: this.$http.adornUrl('/index/announcementsList'),
        method: 'get',
        params: this.$http.adornParams({
          'page': 1,
          'limit':20,
        })
      }).then(({data}) => {
        if (data && data.code === 0) {
          this.list = data.page.list
        } else {
          this.list = []
        }
      })
    }

  },
  mounted() {
    this.getDataList()
  }
};
</script>

<style scoped>
.notic-bar {
  display: flex;
  margin: 2px;
  padding: 0;
}

.notice-bar-container {
  background: rgba(245, 148, 0, 0.5); /* 背景颜色为 #f59400，透明度为 0.8 */
  border-radius: 6px;
  display: flex;
  width: calc(100% - 30px);
  height: 20px;
  overflow: hidden;
  margin: 0 0 0 6px;
}

.notice-img {
  width: 22px;
  height: 22px;
}

.notice-bar__wrap {
  margin-left: 10px;
  display: flex;
  animation: move 20s linear infinite;
  line-height: 20px;
  color: #f5f6f7;
  font-size: 14px;
  font-weight: bold;
}

.notice-bar__wrap_text {
  width: max-content;
  min-width: 100px;
}

@keyframes move {
  0% {
    transform: translateX(100%);
  }
  100% {
    transform: translateX(-100%);
  }
}
</style>
